package com.ruoyi.quartz.task;

import com.alibaba.fastjson2.JSONObject;
import com.crm.custinfo.domain.CustInfo;
import com.crm.custinfo.service.ICustInfoService;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.http.HttpPostUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 回传接口，通过接口获取
 * 
 * @author ruoyi
 */
@Slf4j
@Component("dataFeedbackTask")
public class DataFeedbackTask
{
    private final String url="https://wqbapi.veredloanweb.com/xiaowei-api//out/api/update/standard";
    @Autowired
    private ICustInfoService custInfoService;
    //
    public void exceute()
    {
        String orgId = "101737";
        int success = 0;
        Map<String, Object> params = new HashMap<>();
        params.put("beginupdateTime",DateUtils.parseDateToStr("yyyy-MM-dd",DateUtils.addDay(DateUtils.getNowDate(), -10)));
        Map<String, Object> data = new HashMap<>();
        data.put("orgId", orgId);
        CustInfo custInfo = new CustInfo();
        custInfo.setChannelSource("318");
        custInfo.setParams(params);
        List<CustInfo> list = custInfoService.selectCustInfoList2(custInfo);
        for (CustInfo info : list) {
            try {
                data.put("phoneMd5", info.getMd5val());
                data.put("dataStandard", getDataStandard(info));
                JSONObject result = HttpPostUtils.postJSON(url, data);
                if (result != null && result.getIntValue("code") == 1000) {
                    success++;
                }
            } catch (Exception e) {
                log.error("xw通回传异常", e);
            }
        }
        log.info("xw回传成功数：" + success);
    }
    /**
     * 数据判别标准：
     * 0:0星数据；  2：未接
     * 1:捣乱申请； 1：捣乱
     * 2:无效数据；  1：捣乱
     * 3:外地申请；  3：外地
     * 4:2星数据；  4：2星数据
     * 5:3星数据;  5：优质客户
     * 6:4星数据；  5：优质客户
     * 7:重要客户；  5：优质客户
     * 8:小贷重要；  4：2星数据
     * 9:小贷次要   4：2星数据
     *
     * 2024-09-01 改新回传
     *
     *
     */
    private int getDataStandard(CustInfo info) {
        int feedbackType = 2;
        if ("1".equals(info.getStarLevel())) {
            feedbackType = 1;
        } else if ("2".equals(info.getStarLevel())) {
            feedbackType = 4;
        } else if ("3".equals(info.getStarLevel())) {
            feedbackType = 5;
        } else if ("4".equals(info.getStarLevel())) {
            feedbackType = 5;
        } else if ("5".equals(info.getStarLevel())) {
            feedbackType = 5;
        } else if ("7".equals(info.getStarLevel())) {
            feedbackType = 4;
        } else if ("8".equals(info.getStarLevel())) {
            feedbackType = 4;
        } else if ("9".equals(info.getStarLevel())) {
            feedbackType = 1;
        } else if ("98".equals(info.getStarLevel())) {
            feedbackType = 3;
        }
        //20240424 异地不在星级里面，从状态取
        if (info.getStatus().equals("8")) {
            feedbackType = 3;
        }
        return feedbackType;
    }
    public void ryParams(String params)
    {
        System.out.println("执行有参方法：" + params);
    }

    public void ryNoParams()
    {
        System.out.println("执行无参方法");
    }
}
